package com.client.smartauction;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import org.json.JSONObject;

public class TcpSocket {

	private Socket mTcpSocket;
	private InputStream mTcpInput;
	private OutputStream mTcpOutput;


	private String mServerIP;
	public int mServerPortNum;

	public TcpSocket(String serverIp, int serverPort) {

		mServerIP = serverIp;
		mServerPortNum = serverPort;
		try {
			mTcpSocket = new Socket(mServerIP, mServerPortNum);
			mTcpInput = mTcpSocket.getInputStream(); 
			mTcpOutput = mTcpSocket.getOutputStream();

		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	public void sendMsg(JSONObject jsonobj)
	{
		try {
			if(mTcpSocket.isConnected())
			{
			mTcpOutput.write(jsonobj.toString().getBytes());
			mTcpOutput.flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

